package com.appliance.chamliga;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.appliance.chamliga.download.DownloadHtmlModifyThread;
import com.appliance.chamliga.preference.PrefActivity;
import com.appliance.chamliga.rss.RssActivity;

public class MenuActivity extends RootActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);

		SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
		if (sharedPrefs.getBoolean("perform_download", true)) {
			// Thread rssT = new DownloadRssThread(getApplicationContext());
			// rssT.start();
			Thread htmlT = new DownloadHtmlModifyThread(htmlVmNewsLink, directory, htmlVmNewsFilename,
					htmlVmNewsExtension, false);
			htmlT.start();
			Thread htmls = new DownloadHtmlModifyThread(
					"http://www.copenhagen2011.dk/m/index.php?p=menu/side.php&menu=8", directory, "schedule",
					htmlVmNewsExtension, false);
			htmls.start();
		}

		final Button[] b = { (Button) findViewById(R.id.b1), (Button) findViewById(R.id.b2),
				(Button) findViewById(R.id.b3), (Button) findViewById(R.id.b4), (Button) findViewById(R.id.b5), };

		for (final Button button : b) {
			button.setOnClickListener(new OnClickListener() {

				public void onClick(View arg0) {
					Intent intent = new Intent(MenuActivity.this, RssActivity.class);
					intent.removeExtra("url");
					switch (button.getId()) {
					case R.id.b1:
					default:
						intent = new Intent(MenuActivity.this, BrowserActivity.class);
						intent.putExtra("path", "file://" + htmlVmNewsFilePath);
						break;
					case R.id.b2:
						intent = new Intent(MenuActivity.this, BrowserActivity.class);
						intent.putExtra("path", "file://" + htmlscheduleFilePath);
						// intent.putExtra("url", rssUciNews);
						break;
					case R.id.b3:
						intent = new Intent(MenuActivity.this, BrowserActivity.class);
						intent.putExtra(
								"path",
								"http://maps.google.dk/maps/ms?msid=218310645589935189017.00049ae473341c5536bac&msa=0&ll=55.812375,12.511883&spn=0.076008,0.129261");
						break;
					case R.id.b4:
						intent = new Intent(MenuActivity.this, ResultActivity.class);
						break;
					case R.id.b5:
						intent = new Intent(MenuActivity.this, PrefActivity.class);
						break;
					}
					startActivity(intent);
				}
			});
		}
	}
}
